package com.yenlien.traceyun.usercenter.entity;

import com.yenlien.traceyun.webase.entity.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.lang.reflect.Field;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-03
 * @description: 企业资料
 **/
@Entity
@Table(name = "t_company")
@Data
public class Company extends BaseEntity {

    private String dockProvince;    // 是否已对接 四川省平台  县域平台溯源对接   1=已对接  2或者null=为对接

    @Column(name = "name", length = 50)
    private String name; //企业名称
    @Column(name = "abbreviation", length = 50)
    private String abbreviation;    //企业简称

    private String iotName = "物联网平台";     // 物联网名称 该字段为空则没有物联网平台页面

    // 名企名品
    @Column(columnDefinition = "text")
    private String content;             // JSON数组, [{}]   type(经营品种)  price(当前报价)  time(上市时间)  img(图片)


    @Column(name = "area", length = 100)
    private String area;     //区域
    @Column(name = "credit_code", length = 18)    //统一社会代码
    private String creditCode;
    @Column(name = "address", length = 100)
    private String address;    //注册地址
    @Column(name = "term", length = 100)
    private String term;//经营期限

    @Column(name = "region", length = 100)
    private String region;

    /**
     * 父企业
     */
    @Column(name = "parent_id", length = 32)
    private String parentId;

    /**
     * 父企业名称
     */
    @Column(name = "parent_name", length = 100)
    private String parentName;

    @Column(length = 200)
    private String licenseImg; //公司执照
    @Column
    private String legalName;//法定代表人
    @Column
    private String legalPhone;//法定人电话
    @Column
    private String legalTime;//法定人证件期限
    @Column
    private String legalID;//法定人身份证
    @Column
    private String legalImg;//法定人身份证头像
    @Column
    private String legalIDImg;//法定人身份证背面
    @Column
    private String operateName;//运营代表人
    @Column
    private String operatePhone;//运营人电话
    @Column
    private String operateTime;//运营人证件期限
    @Column
    private String operateID;//运营人身份证
    @Column
    private String operateImg;//运营人身份证头像
    @Column
    private String operateIDImg;//运营人身份证背面
    @Column(length = 20)
    private String liaisonName;    //企业联系人
    @Column(name = "phone", length = 14)
    private String phone;    //企业联系电话号码
    @Column
    @Lob
    private String introduce;   //企业介绍
    @Column
    private String coverImg;   //企业封面
    @Column
    private String remark; //摘要，备注
    @Column(name = "createtime")
    private String createtime;   //创建时间
    @Column(name = "examined", length = 1)
    private String examined;     //审核通过 0驳回，1通过
    @Column(name = "expiretime")
    private String expiretime;     //过期时间

    @Column(name = "expiretime_end")
    private String expiretimeEnd;//过期结束时间

    @Column(name = "user_id")
    private String userId;     //绑定的用户id
    @Column
    private String type;    //1企业 2 政府 3代理商,0系统内置
    @Column
    private int state; //0有效数据；1无效数据
    @Column
    private String logoImg; //长方形企业log
    @Column
    private String logozImg; //正方形企业log

    @Column(name = "operatePosition", length = 50)
    private String operatePosition;       //职位

    @Column(name = "platform", length = 60)
    private String platform; //平台名字


    private String fruitType; //果园类型        1=普通果园  2=智慧果园
    private String compType; //果园组织类型        1=公司  2=合作社  3=私人

    @Column(columnDefinition = "text")
    private String fruitProd;    // 果业产值情况 JSON字符串  {prodNum=产量, prodVal=产值, coordinate=坐标, url=果园链接}

    /**
     * 扫码log
     */
    @Column(name = "scan_img", length = 100)
    private String scanImg;

    @Column(name = "app_id", length = 100)
    private String appId;           //关联的平台


    @Transient
    private List<OtherMaterial> materialList;//证件证书集合
    @Transient
    private String materials;//证件证书前端传入时已字符串传入
    @Transient
    private User us;//用户
    @Transient
    private String user;//用户前端传入时已字符串传入
    @Transient
    private List<CompanyCustomAppVersion> versions;//企业应用
    @Transient
    private String versionsString;//用户前端传入时已字符串传入


    public void setImgName(String originalFilename, String newName) throws IllegalAccessException {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            if (field.getName().endsWith("Img")) {
                field.setAccessible(true);
                String value = (String) field.get(this);
                if (value != null && value.contains(originalFilename)) {
                    field.set(this, value.replace(originalFilename, newName));
                    return;
                }
            }
        }


    }

}
